using System;
using System.Collections;
using UnityEngine;

public class tk2dWidthStretch : MonoBehaviour
{
	private void Start()
	{
		base.StartCoroutine(this.CoStretchScale());
	}

	private IEnumerator CoStretchScale()
	{
		for (int i = 0; i < 10; i++)
		{
			if (this.sizeX != this.cam.ScreenExtents.width)
			{
				this.StretchScale();
				this.sizeX = this.cam.ScreenExtents.width;
			}
			yield return new WaitForSeconds(0.05f);
		}
		yield break;
	}

	public void StretchScale()
	{
		base.gameObject.transform.localScale = Vector3.one;
		Bounds renderBound = this.GetRenderBound(base.gameObject);
		Rect screenExtents = this.cam.ScreenExtents;
		this.sprite.scale = new Vector3(this.sprite.scale.x * (screenExtents.width / renderBound.size.x), this.sprite.scale.y, this.sprite.scale.z);
	}

	private Bounds GetRenderBound(GameObject go)
	{
		Bounds result = new Bounds(go.transform.position, Vector3.zero);
		Renderer component = go.GetComponent<Renderer>();
		result.Encapsulate(component.bounds);
		return result;
	}

	public tk2dCamera cam;

	public tk2dSlicedSprite sprite;

	private float sizeX;
}
